package com.example.history.controller;


import com.example.common.dtos.ResponseResult;
import com.example.history.entity.History;
import com.example.history.service.IHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 凡哥哥
 * @since 2023-11-25
 */
@RestController
@RequestMapping("/history")
@Api(value = "浏览历史控制器")
public class HistoryController {

    @Autowired
    private IHistoryService historyService;

    /**
     * 添加历史记录,到Redis中
     *
     * @param history
     * @return
     */
    @ApiOperation("添加历史记录,到Redis中")
    @PostMapping
    public ResponseResult historyAdd(@RequestBody History history) {
        historyService.historyAdd(history);
        return ResponseResult.okResult("");
    }

    /**
     * 在Redis中获取历史记录
     *
     * @param userId
     * @return
     */
    @ApiOperation("在Redis中获取历史记录")
    @GetMapping("/{userId}")
    public List<History> historyList(@PathVariable("userId") Long userId) {
        return historyService.historyList(userId);
    }

    /**
     * 删除历史记录
     *
     * @param ids
     * @return
     */
    @ApiOperation(value = "删除历史记录")
    @GetMapping("/deleteHistorys")
    public ResponseResult delete(String ids, int userId) {
        return historyService.deleteHistorys(ids,userId);
    }
}

